import { createRouter, createWebHistory } from 'vue-router'

// createRouter 创建路由实例，===> new VueRouter()
// 1. history模式: createWebHistory()   http://xxx/user
// 2. hash模式: createWebHashHistory()  http://xxx/#/user

// vite 的配置 import.meta.env.BASE_URL 是路由的基准地址，默认是 ’/‘
// https://vitejs.dev/guide/build.html#public-base-path

// 如果将来你部署的域名路径是：http://xxx/my-path/user
// vite.config.ts  添加配置  base: my-path，路由这就会加上 my-path 前缀了

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    { path: '/login', component: () => import('@/views/login/LoginPage.vue') },
    {
      path: '/',
      component: () => import('@/views/layout/LayoutContainer.vue'),
      redirect: '/postList/recommend',
      children: [
        {
          path: '/postList/recommend',
          component: () => import('@/views/postList/PostListRecommend.vue')
        },
        {
          path: '/postList/message',
          component: () => import('@/views/postList/PostListMessage.vue')
        },
        {
          path: '/postList/detail',
          component: () => import('@/views/postList/PostListDetail.vue')
        },
        {
          path: '/postList/upload',
          component: () => import('@/views/postList/PostListUpload.vue')
        },
        {
          path: '/user/profile',
          component: () => import('@/views/user/UserProfile.vue')
        }
      ]
    }
  ]
})

export default router
